<?php
declare(strict_types=1);

use Phinx\Migration\AbstractMigration;

final class CreateScheduleManage extends AbstractMigration
{
    public function up()
    {
        $table = $this->table('schedule_manage', ['id' => false, 'primary_key' => ['id'], 'engine' => 'InnoDB', 'collation' => 'utf8mb4_general_ci', 'comment' => '排班管理表']);
        $table->addColumn('id', 'integer', ['identity' => true, 'signed' => false, 'limit' => 11, 'comment' => '主键ID'])
            ->addColumn('title', 'string', ['default' => '', 'limit' => 128, 'comment' => '标题'])
            ->addColumn('type', 'enum', ['values' => 'project,default', 'default' => 'default', 'comment' => '排班类型:默认通用(default),项目(project)'])
            ->addColumn('project_id', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '项目ID'])
            ->addColumn('schedule_time', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '排期时间'])
            ->addColumn('is_work', 'enum', ['values' => 'yes,no,default', 'default' => 'default', 'comment' => '是否上班'])
            ->addColumn('tenant_id', 'integer', ['signed' => false, 'limit' => 11, 'default' => 0, 'comment' => '租户id'])
            ->addColumn('created_by', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '创建者'])
            ->addColumn('updated_by', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '编辑者'])
            ->addColumn('created', 'integer', ['null' => false, 'default' => 0, 'limit' => 11, 'signed' => false, 'comment' => '创建时间',])
            ->addColumn('updated', 'integer', ['signed' => false, 'default' => 0, 'limit' => 11, 'comment' => '更新时间'])
            ->save();
        // 添加索引
        $table->addIndex(['project_id', 'schedule_time'], ['unique' => true, 'name' => 'idx_project_id_schedule_time'])->save();
    }

    public function down()
    {
        $this->table('schedule_manage')->drop()->save();
    }
}
